package jjn.weekly;

/**
 * @author Jiang Jining
 * @since 2023-06-04 10:47
 */
public class LeetCode6472 {
    public long matrixSumQueries(int n, int[][] queries) {
        boolean[] columns = new boolean[n];
        boolean[] rows = new boolean[n];
        int availableRows = n;
        int availableColumns = n;
        long total = 0;
        for (int i = queries.length - 1; i >= 0; i--) {
            int[] query = queries[i];
            int index = query[1];
            int target = query[2];
            int count = 0;
            if (query[0] == 0) {
                if (rows[index]) {
                    continue;
                }
                rows[index] = true;
                count = availableColumns;
                availableRows--;
            }
            if (query[0] == 1) {
                if (columns[index]) {
                    continue;
                }
                columns[index] = true;
                count = availableRows;
                availableColumns--;
            }
            total += (long) target * count;
        }
        return total;
    }
}
